package com.api.wall.searchevents;

import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.zyncro.api.IWallApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.EventApi;
import com.zyncro.api.model.PagedItemsResultApi;
import com.zyncro.api.model.SearchFilterApiType;

@ContextConfiguration(locations = "classpath:/wall/wall-inbox.xml")
public class SearchEvents extends AbstractApiTest {

	@Value("#{user_toGet.appId}")
	private String userUrn;

	@Value("#{user_toGet.password}")
	private String userPassword;

	@Value("#{user_toGet.searchText}")
	private String text = "e";

	@Value("#{user_toGet.totalSearch}")
	private int totalSearch;

	@Value("#{user_toGet.totalSearchCompanyFeed}")
	private int totalSearchCompanyFeed;

	@Value("#{user_toGet.totalSearchDepartment}")
	private int totalSearchDepartment;

	@Value("#{user_toGet.totalSearchGroup}")
	private int totalSearchGroup;

	@Value("#{user_toGet.totalSearchPersonalFeed}")
	private int totalSearchPersonalFeed;

	@Value("#{user_toGet.totalSearchPrivateMessages}")
	private int totalSearchPrivateMessages;

	@Value("#{user_toGet.totalSearchZlinks}")
	private int totalSearchZlinks;

	@BeforeClass
	protected void setParameters() throws Exception {

		getApi().login(userUrn, userPassword);
	}

	@Test
	public void testSearchWallAll() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		SearchFilterApiType searchType = null;
		List<String> groups = null;
		List<String> users = null;
		String fromDate = null;
		String toDate = null;
		boolean onlyResultSize = false;
		boolean includeHtml = false;
		boolean includeProperties = false;

		PagedItemsResultApi<EventApi> result = getApi().getService(IWallApiService.class).searchEvents(pageNumber, itemsPerPage, text,
				searchType, groups, users, fromDate, toDate, onlyResultSize, includeHtml, includeProperties);

		Assert.assertEquals(result.getTotalItems(), totalSearch, "Total search items");
	}

	@Test
	public void testSearchWallOnlyResult() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		SearchFilterApiType searchType = null;
		List<String> groups = null;
		List<String> users = null;
		String fromDate = null;
		String toDate = null;
		boolean onlyResultSize = true;
		boolean includeHtml = false;
		boolean includeProperties = false;

		PagedItemsResultApi<EventApi> result = getApi().getService(IWallApiService.class).searchEvents(pageNumber, itemsPerPage, text,
				searchType, groups, users, fromDate, toDate, onlyResultSize, includeHtml, includeProperties);

		Assert.assertEquals(result.getTotalItems(), totalSearch, "Total search items");
	}

	@Test
	public void testSearchWallCompanyFeed() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		SearchFilterApiType searchType = SearchFilterApiType.COMPANY_FEED;
		List<String> groups = null;
		List<String> users = null;
		String fromDate = null;
		String toDate = null;
		boolean onlyResultSize = false;
		boolean includeHtml = false;
		boolean includeProperties = false;

		PagedItemsResultApi<EventApi> result = getApi().getService(IWallApiService.class).searchEvents(pageNumber, itemsPerPage, text,
				searchType, groups, users, fromDate, toDate, onlyResultSize, includeHtml, includeProperties);

		Assert.assertEquals(result.getTotalItems(), totalSearchCompanyFeed, "Total search company feed items");
	}

	@Test
	public void testSearchWallDepartment() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		SearchFilterApiType searchType = SearchFilterApiType.DEPARTMENT;
		List<String> groups = null;
		List<String> users = null;
		String fromDate = null;
		String toDate = null;
		boolean onlyResultSize = false;
		boolean includeHtml = false;
		boolean includeProperties = false;

		PagedItemsResultApi<EventApi> result = getApi().getService(IWallApiService.class).searchEvents(pageNumber, itemsPerPage, text,
				searchType, groups, users, fromDate, toDate, onlyResultSize, includeHtml, includeProperties);

		Assert.assertEquals(result.getTotalItems(), totalSearchDepartment, "Total search departmentitems");
	}

	@Test
	public void testSearchWallGroup() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		SearchFilterApiType searchType = SearchFilterApiType.GROUP;
		List<String> groups = null;
		List<String> users = null;
		String fromDate = null;
		String toDate = null;
		boolean onlyResultSize = false;
		boolean includeHtml = false;
		boolean includeProperties = false;

		PagedItemsResultApi<EventApi> result = getApi().getService(IWallApiService.class).searchEvents(pageNumber, itemsPerPage, text,
				searchType, groups, users, fromDate, toDate, onlyResultSize, includeHtml, includeProperties);

		Assert.assertEquals(result.getTotalItems(), totalSearchGroup, "Total search group items");
	}

	@Test
	public void testSearchWallPersonalFeed() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		SearchFilterApiType searchType = SearchFilterApiType.PERSONAL_FEED;
		List<String> groups = null;
		List<String> users = null;
		String fromDate = null;
		String toDate = null;
		boolean onlyResultSize = false;
		boolean includeHtml = false;
		boolean includeProperties = false;

		PagedItemsResultApi<EventApi> result = getApi().getService(IWallApiService.class).searchEvents(pageNumber, itemsPerPage, text,
				searchType, groups, users, fromDate, toDate, onlyResultSize, includeHtml, includeProperties);

		Assert.assertEquals(result.getTotalItems(), totalSearchPersonalFeed, "Total search personal feed items");
	}

	@Test
	public void testSearchWallPrivateMessages() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		SearchFilterApiType searchType = SearchFilterApiType.PRIVATE_MESSAGES;
		List<String> groups = null;
		List<String> users = null;
		String fromDate = null;
		String toDate = null;
		boolean onlyResultSize = false;
		boolean includeHtml = false;
		boolean includeProperties = false;

		PagedItemsResultApi<EventApi> result = getApi().getService(IWallApiService.class).searchEvents(pageNumber, itemsPerPage, text,
				searchType, groups, users, fromDate, toDate, onlyResultSize, includeHtml, includeProperties);

		Assert.assertEquals(result.getTotalItems(), totalSearchPrivateMessages, "Total search private messages items");
	}

	@Test
	public void testSearchWallZlinks() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		SearchFilterApiType searchType = SearchFilterApiType.ZLIKS;
		List<String> groups = null;
		List<String> users = null;
		String fromDate = null;
		String toDate = null;
		boolean onlyResultSize = false;
		boolean includeHtml = false;
		boolean includeProperties = false;

		PagedItemsResultApi<EventApi> result = getApi().getService(IWallApiService.class).searchEvents(pageNumber, itemsPerPage, text,
				searchType, groups, users, fromDate, toDate, onlyResultSize, includeHtml, includeProperties);

		Assert.assertEquals(result.getTotalItems(), totalSearchZlinks, "Total search zlink items");
	}
}
